<?php
include_once '..'.DIRECTORY_SEPARATOR.'common'.DIRECTORY_SEPARATOR.'admin-header.php';
error_reporting(0);
session_start();
include_once '..'.DIRECTORY_SEPARATOR.'db-connection'.DIRECTORY_SEPARATOR.'conn.php';
include_once 'clsEssentials.php';
include_once 'clsFormLayouts.php';
$arrUserData = array();
$objMyClass = new clsEssentials();
$objFormPopulateClass = new clsFormLayouts();
/*if(!isset($_SESSION["UserName"]))
{
	header("../index.php");
	exit;
}*/
$userName = $_SESSION["UserName"];
?>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../gooeymenu.js"></script>
<link rel="stylesheet" type="text/css" href="../gooeymenu.css" />
<link rel="stylesheet" type="text/css" href="admin-menu.css" />
<div id="outlineborder">
 <div class="main">
     <div class="rptcontenttop">
	   <div class="rptcontenttopleft">
	      <?php include '../common/admin-side-bar.php'; ?>
	   </div>
	   <div class="rptcontenttopright">
	      <div id="maincontent">
			<div class="clean-gray">
		    Welcome, <?php echo ucfirst($userName); ?>
		   </div>
		   <div id="linehead">
		   </div>
		   <div class="contenttext">
		   <div class="coutline" style="padding:25px;">
		 		<?php 
		 		if($_REQUEST['page']=="change-category")
		 		{
		 			print $objFormPopulateClass->frmChangeCategories();
		 		}
		 		else if($_REQUEST['page']=="change-subcategory")
		 		{
		 			print $objFormPopulateClass->frmChangeSubCategories();
		 		}
				else if($_REQUEST['page']=="upload-video")
		 		{
		 			print $objFormPopulateClass->frmUploadVideos();
		 		}
		 		else if($_REQUEST['page']=="user-details")
		 		{
		 			print $objFormPopulateClass->frmUserDetails();
		 		}
		 		else if($_REQUEST['page']=="see-all-videos")
		 		{
		 			print $objFormPopulateClass->frmVideoAllVideos();
		 		}
		 		//
		 		
		 		?>
			</div>
		   </div>
		  </div>
		 
	   </div>
</div>
</div>
</div>
<script type="text/javascript">
function divshow(divname)
{
	document.getElementById(divname).style.display="block";
}

function showAllSubCategories()
{
	document.getElementById("showAllSubCategories").style.display="block";
}

/*
 * The following function inserts the category name in DB
 */

function doCheckCategoryName()
{
	var catName = $("#txtCategoryName").val();
	if(catName.length==0)
	{
		alert("Category name can not be blank. Thank you.");
		return false;
	}
	else
	{
		$.post("database-inserts.php",{catname:catName,action:"insertcategory"},function (data){
			if(data==1)
			{
				alert("Category Successfully Added. Thank you");
			}
			else if(data==2)
			{
				alert("Category with same name already exists. Please try with some other category name");
			}
			else
			{
				alert("There was a problem in connection. Please try again later. Thank you");
			}
		},"text");	
	}
	
}


function doCheckSubCategoryName()
{
	var SubcatName = $("#txtSubCategoryName").val();
	var catid = $("#ddlcategoryName").val();
	var strErrMsg = "";
	if(SubcatName.length==0)
	{
		strErrMsg +="Subcategory name can not be blank.";
		strErrMsg +="\n";
	}
	if(catid=="-select-")
	{
		strErrMsg +="Please select a valid category.";
		strErrMsg +="\n";
	}
	if(strErrMsg.length==0)
	{
		$.post("database-inserts.php",{catid:catid,subcatname:SubcatName,action:"insertsubcategory"},function (data){
			if(data==1)
			{
				alert("Sub-category Successfully Added. Thank you");
			}
			else
			{
				alert("There was a problem in connection. Please try again later. Thank you");
			}
		},"text");	
	}
	else
	{
		alert(strErrMsg);
	}
}

function categoryAction(action, id)
{
	if((action.length>0) && (id.length>0))
	{
		$.post("database-inserts.php",{catid:id,action:action},function (data){
			if(data==1)
			{
				alert("Category "+ action +" Successfull. Thank you");
			}
			else
			{
				alert("There was a problem in connection. Please try again later. Thank you");
			}
		},"text");	
	}
		
}


function showEditCategoryDiv(categoryName, catId)
{
	document.getElementById("EditCategories").style.display="block";
	document.getElementById("txtEditCategoryName").value=categoryName;
	document.getElementById("hdnEditCategoryId").value= catId;
}


function doUpdateCategoryName()
{
	var categoryId = $("#hdnEditCategoryId").val();
	var categoryName = $("#txtEditCategoryName").val();
	
	if($("#txtEditCategoryName").val()=="")
	{
		alert("Category Name can not be blank");
		return false;
	}
	else
	{
		$.post("database-inserts.php",{catid:categoryId,categoryname:categoryName,action:"update-category"},function (data){
			if(data==1)
			{
				alert("Category Successfully updated. Thank you");
			}
			else
			{
				alert("There was a problem in connection. Please try again later. Thank you");
			}
		},"text");	
	}
}

//Following function uploads the videos to the server.
//frmUploadVideo
$("#frmUploadVideo").submit(function() {	
	        var vidName = $("#uploaded").val();
	        var vidTitle = $("#txt_vid_title").val();
	        var vidDesc = $("#txtarea_vid_desc").val();
	  		//alert(vidName);
	  		if(vidName == 0 || vidName == "")
	  		{
	  			alert("Video name can not be blank. Thank you.");
	  			return false;
	  		}else if(vidTitle == ""){
	  				alert("Video title can not be blank. Thank you.");
	  				return false;
		  		}else if(vidDesc==""){
		  			alert("Video desc can not be blank. Thank you.");
	  				return false;
			  		}else{
				return true;
			}	     
	    });


function populateSubcategory()
{
	var selectedCategory = $("#ddlcategoryName").val();
	
		$.post("populate-subcategory.php",{categoryname:selectedCategory},function (data) {
			document.getElementById("ddlSubCategorySelect").innerHTML =data;
		},"text")
	
}

function Activate_Deactivate_User(type,id)
{
	$.post("database-inserts.php",{action:type,id:id},function (data){
	if(data==1)
	{
		alert("User has been activated.");	
	}
	},"text");	
}

function upgradeUser(id)
{
	
}

function playVideo(id)
{
	window.open("../video.php?v="+id,"_self");
}

</script>
 <?php
	include_once '../common/admin-footer.php';
 ?>